package com.poc.party.tool;

import com.meta.nd.util.NodeUtil;
import com.meta.nd.vo.Nd;
import com.meta.nd.vo.Nv;
import com.poc.party.vo.PartyAccountVO;
import com.poc.party.vo.PartyVO;

public class PartyNvTool {
	
	public static Nv partyVO2Nv (PartyVO partyVO,Nd parytNd ) {
		
		if ( partyVO == null )
			return null;
		
		Nv nv = NodeUtil.nd2Nv(parytNd);
		
		nv.setId(partyVO.getId());
		nv.setStringFvByName("partyCode", partyVO.getPartyCode());
		
		nv.setStringFvByName("partyName", partyVO.getPartyName());	
		nv.setDateFvByName("birthday", partyVO.getBirthday());	
		nv.setStringFvByName("certType", partyVO.getCertType());
		nv.setStringFvByName("certId",partyVO.getCertId());
		nv.setStringFvByName("gender", partyVO.getGender());
		nv.setStringFvByName("address", partyVO.getAddress());
		nv.setStringFvByName("postCode",partyVO.getPostCode());
		nv.setStringFvByName("telNo", partyVO.getTelNo());
		nv.setStringFvByName("mobileNo", partyVO.getMobileNo());		
		
		nv.setStringFvByName("contact", partyVO.getContact());
		nv.setStringFvByName("contactMobileNo", partyVO.getContactMobileNo());	
		nv.setStringFvByName("vipType", partyVO.getVipType());
		nv.setDateFvByName("createDate", partyVO.getCreateDate());	
		nv.setStringFvByName("branch", partyVO.getBranch());
		
		
		Nd childNd = parytNd.getFirstChild();
		
		for ( PartyAccountVO account : partyVO.getPartyAccounts() ) {
			Nv childNv = NodeUtil.nd2Nv(childNd);	
			childNv.setId(account.getId());
			childNv.setStringFvByName("bankName", account.getBankName());
			childNv.setStringFvByName("accountNo",account.getAccountNo());
			childNv.setStringFvByName("accountName", account.getAccountName());
			childNv.setStringFvByName("address", account.getAddress());
			childNv.setStringFvByName("postCode", account.getPostCode());
		
			nv.addChildNv(childNd.getNdName(),childNv);
		}
		
		return nv;
		
	}
	
	public static PartyVO nv2PartyVO(Nv partyNv ) {
		
		if ( partyNv == null )
			return null;
		
		PartyVO party = new PartyVO();
		
		party.setId(partyNv.getId());
		party.setPartyCode(partyNv.getRawStringByName("partyCode"));
		party.setPartyName(partyNv.getRawStringByName("partyName"));
		party.setBirthday(partyNv.getRawDateByName("birthday"));
		party.setCertType(partyNv.getRawStringByName("certType"));
		party.setCertId(partyNv.getRawStringByName("certId"));
		party.setGender(partyNv.getRawStringByName("gender"));
		party.setAddress(partyNv.getRawStringByName("address"));
		
		party.setPostCode(partyNv.getRawStringByName("postCode"));		
		party.setTelNo(partyNv.getRawStringByName("telNo"));		
		party.setMobileNo(partyNv.getRawStringByName("mobileNo"));		
		
		party.setContact(partyNv.getRawStringByName("contact"));		
		party.setContactMobileNo(partyNv.getRawStringByName("contactMobileNo"));		
		party.setVipType(partyNv.getRawStringByName("vipType"));			
		
		party.setCreateDate(partyNv.getRawDateByName("createDate"));
		party.setBranch(partyNv.getRawStringByName("branch"));		

		if (partyNv.getSingleChildren() != null ) {
		
		for ( Nv childNv : partyNv.getSingleChildren() ) {
				PartyAccountVO account = new PartyAccountVO();
				
				account.setId(childNv.getId());
				account.setAccountName(childNv.getRawStringByName("bankName"));
				account.setAccountName(childNv.getRawStringByName("accountNo"));
				account.setAccountName(childNv.getRawStringByName("accountName"));
				account.setAccountName(childNv.getRawStringByName("address"));
				account.setAccountName(childNv.getRawStringByName("postCode"));
				party.getPartyAccounts().add(account);
				
			}
		}
		
		
		return party;
	}
	

}
